<?php

namespace Admin\Controller;
/**用户控制器
 * Class AgencyController
 * @package Admin\Controller
 */
class AccountController extends AdminController {

    //资金提现
    public function drawList(){
        $limit = LIMIT;
        $get = I('post.');

        $search_data = array();//筛选数据
        $where = array();//条件

        if(IS_POST){
            session('searchdata_users',$get);
        }else{
            if(I('get.p')){
                $this->assign('p',I('get.p'));
            }else{
                session('searchdata_users',null);
            }
            $get = $search_data = session('searchdata_users');
        }


        if(isset($get['user_name']) && $get['user_name'] != ''){
            $search_data['user_name'] = $get['user_name'];
            $where['a.user_name'] = array('like','%'.$get['user_name'].'%');
        }
        $where['b.type']=1;
        $get['sort'] = isset($get['sort'])?$get['sort']:'desc';
        $search_data["sort"] = $get["sort"];
        

        $count = M('account_log')->where($where)->count();
        $Page = new  \Think\Page($count, $limit);// 实例化分页类 传入总记录数

        $Page->setConfig('prev', '上一页');
        $Page->setConfig('next', '下一页');
        $Page->setConfig('last', '末页');
        $Page->setConfig('first', '首页');
        $Page->setConfig('theme', '%FIRST%%UP_PAGE%%LINK_PAGE%%DOWN_PAGE%%END%%HEADER%');
        $show = $Page->show();// 分页显示输出
        $this->assign('page',$show);// 赋值分页输出
        $lists = M('account_log')->alias('b')
            ->join('fas_users a on b.user_id = a.user_id','left')
            ->field('a.user_name,b.*')
            ->where($where)
            ->limit($Page->firstRow . ',' . $Page->listRows)
            ->order("b.id ".$get['sort'])
            ->select();
        // echo M()->getLastsql();
        // exit;
        $this->assign('lists',$lists);
        $p = I('get.p',1);
        $this->assign('p',$p);
        $this->assign('searchs',$search_data);
        $this->display();
    }
//提现操作
    public function drawEdit(){
      if(I('post.btn')){$this->success('');}
      if(IS_POST){
          $data = I('post.');
          $id = $data['id'];
          if(empty($id)){
                $this->error('请选择需要操作的数据');
          }
          $data['admin_user']=NICKNAME;
          $data['paid_time']=time();
          $res = M('account_log')->where(array('id'=>$id))->save($data);

          $log=array(
              'user_id'=>$data['uid'],
              'change_desc'=>$data['admin_note'],
              'change_time'=>$data['paid_time'],
              'user_money'=>$data['money'],
              'change_type'=>3
              );
          M('user_account')->add($log);
          if(is_numeric($res)){
             $this->success('编辑成功');
          }else{
             $this->error('编辑失败');
          }
         exit;
      }else{
         //$res=M('user_drawings')->where(array('id'=>I('id')))->find();
         $res= M('account_log')->alias('b')
              ->join('fas_users a on b.user_id = a.user_id','left')
              ->field('a.user_name,b.*')
              ->where(array('b.id'=>I('id')))
              ->find();
         $this->assign('res',$res);
         $p = I('get.p',1);
         $this->assign('p',$p);
         $this->display();

      }
     
    }

    //充值记录
    public function rechargeList(){
        $limit = LIMIT;
        $get = I('post.');

        $search_data = array();//筛选数据
        $where = array();//条件

        if(IS_POST){
            session('searchdata_users',$get);
        }else{
            if(I('get.p')){
                $this->assign('p',I('get.p'));
            }else{
                session('searchdata_users',null);
            }
            $get = $search_data = session('searchdata_users');
        }


        if(isset($get['user_name']) && $get['user_name'] != ''){
            $search_data['user_name'] = $get['user_name'];
            $where['a.user_name'] = array('like','%'.$get['user_name'].'%');
        }
        $where['b.type']=2;
        $get['sort'] = isset($get['sort'])?$get['sort']:'desc';
        $search_data["sort"] = $get["sort"];
        

        $count = M('account_log')->where($where)->count();
        $Page = new  \Think\Page($count, $limit);// 实例化分页类 传入总记录数

        $Page->setConfig('prev', '上一页');
        $Page->setConfig('next', '下一页');
        $Page->setConfig('last', '末页');
        $Page->setConfig('first', '首页');
        $Page->setConfig('theme', '%FIRST%%UP_PAGE%%LINK_PAGE%%DOWN_PAGE%%END%%HEADER%');
        $show = $Page->show();// 分页显示输出
        $this->assign('page',$show);// 赋值分页输出
        $lists = M('account_log')->alias('b')
            ->join('fas_users a on b.user_id = a.user_id','left')
            ->field('a.user_name,b.*')
            ->where($where)
            ->limit($Page->firstRow . ',' . $Page->listRows)
            ->order("b.id ".$get['sort'])
            ->select();
        // echo M()->getLastsql();
        // exit;
        $this->assign('lists',$lists);
        $p = I('get.p',1);
        $this->assign('p',$p);
        $this->assign('searchs',$search_data);
        $this->display();
    }


}
